package com.shen.JUC.LockTest;

public class Test01 {
    //线程就是一个单独的资源类
    public static void main(String[] args) {
//并发：多线程操作同一个资源类
        Ticket ticket = new Ticket();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                ticket.sell();
            }
        },"A").start();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                ticket.sell();
            }
        },"B").start();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                ticket.sell();
            }
        },"C").start();
    }
}

//资源类oop
class Ticket {
    //属性、方法
    private int number = 20;

    //卖票的方式
    public synchronized void sell() {
        if (number > 0) {
            System.out.println(Thread.currentThread().getName()+number--);
        }

    }
}